<?php
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) { //安全判断
	exit('Access Denied');
}
/**
 *	@name		商品拍卖
 *	@author		Jeffery
 *	@qq			1017756891
 *	@email		1017756891@qq.com
 *	@website	http://www.iweitao.net
**/
// 载入核心处理类
require_once "core.php";
require_once "paipai.class.php";
// error_reporting(E_ALL);
$core = new safe_weitao_plugin_iweitao_paipai;
$globalclass = new threadplugin_iweitao_paipai;

/*************获取分页参数****************/
$page_param = $core->get_page_param();
// 显示所有拍卖商品
/***获得列表内容********************************/ 
$where = '';
// 获得交易成功
if($core->_get('show')){
	switch ($core->_get('show')) {
		case 'deal':
			$where = "a.status=4 and b.status=4";
			break;
	}
	
}
// 总条数
$count = count($globalclass->get_deal_orders_width_buy($where));


$limit = $page_param['mulipage'] . ',' . $page_param['pagecount'];

$getcount = $globalclass->get_deal_orders_width_buy($where,$limit);

// var_dump($getcount);


// var_dump($core->_get('ac'));

if($core->_get('ac')){

	// 退款
	if($core->_get('ac') == 'return' && $core->_get('acdo',1)){
		$tid = $core->_get('acdo',1);
		$info = $globalclass->get_goods_buy_order_by_tid($tid);
		if($info){
			// 返回买家积分
			// 不是退款申请状态，错误返回
			if($info['order_status'] != -1 || $info['status'] != 3){
				cpmsg("错误返回",'','error');
				exit;
			}
			// 更新数据表
			DB::update("paipai_goods",array('status'=>4),"`gid` = " . $info['gid']);

			DB::update("paipai_buy",array('status'=>-2),"`gid` = ".$info['gid']." and `orderid` = " . $info['orderid']);

			$return_price = $info['order_price'];
			$re = updatemembercount($info['order_uid'],array("extcredits$credit" => "$return_price"),true,'RCV',$info['order_uid'],'积分转账转入 - 拍卖退款','商品拍卖退款，退还积分');
			// 消息提示
			$msg = "商品 <a href='forum.php?mod=viewthread&tid=$tid' target='_blank'>" . $info['title'] . "</a> 退款申请成功，积分已退还，请查收";
			notification_add( $info['order_uid'],'post', $msg ,array(),$system = 1);
			$msg = "退款成功,返还积分 " . $return_price;
			cpmsg($msg,'','succeed');
			exit;
		}
		cpmsg("错误返回",'','error');
		exit;
	}


	

	// 删除拍卖品
	if($core->_get('ac') == 'delete' && $core->_get('acdo',1)) {
		DB::query("DELETE  FROM `".DB::table("paipai_goods")."` WHERE `tid` = '".$core->_get('acdo',1)."'");
		if(DB::affected_rows()){
			cpmsg("删除成功",'','succeed');
			exit;
		}else{
			cpmsg("删除失败",'','succeed');
			exit;
		}
	}


}


// 获得并设置url
$url = $_SERVER['REQUEST_URI'];

$uarr = parse_url($url);
parse_str($uarr['query'],$ustr);
if(isset($ustr['page']))  unset($ustr['page']);
$url = $uarr['path'] . '?' . http_build_query($ustr);


// 获得分页输出
$page_show = multi($count, $page_param['pagecount'], $page_param['page'], $url, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE);


include template("iweitao_paipai:admin");
